//
//  HWNewCommentsTableViewCell.m
//  HWanGame
//
//  Created by 陈道斌 on 2021/9/1.
//  Copyright © 2021 Chendaobin. All rights reserved.
//

#import "HWNewCommentsTableViewCell.h"
// #import "ClickTextView.h"
#import "HWwenzipinglunViewController.h"
@interface HWNewCommentsTableViewCell()
// @property(strong,nonatomic) ClickTextView *neirongtextview;



@end

@implementation HWNewCommentsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        
    }
    
    return  self;
    
    
}



- (void)setupUI {
    
    ClickTextView *clickTextView = [[ClickTextView alloc] initWithFrame:CGRectMake(60, 0, kScreenW-60-15, 30)];
    // self.clickTextView
    clickTextView.layoutManager.allowsNonContiguousLayout = NO;
    clickTextView.textContainerInset=  UIEdgeInsetsMake(8, 10, 0, 10);
    clickTextView.userInteractionEnabled = NO;
    [self.contentView addSubview:clickTextView];
    
    // 方便测试，设置textView的边框已经背景
    clickTextView.backgroundColor = RGB(247, 248, 248);
   //  clickTextView.backgroundColor = [UIColor whiteColor];
//    clickTextView.layer.borderWidth = 1;
//    clickTextView.layer.borderColor = [UIColor redColor].CGColor;
    clickTextView.font = [UIFont systemFontOfSize:14];
    clickTextView.textColor = RGB(120, 120, 120);
    self.neirongtextview =clickTextView;
    
  
//    NSString *content = @"首先:感谢您的信任和使用策》";
//    self.neirongtextview.text = content;
//
//    NSRange range1 = [content rangeOfString:@"首先:"];
//    [clickTextView setUnderlineTextWithRange:range1 withUnderlineColor:RGB(51, 51, 51) withClickCoverColor:nil withBlock:^(NSString *clickText) {
//        NSLog(@"clickText = %@",clickText);
//
//
//    }];
    
//
    
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, kScreenW-60-15, 20)];
    label.backgroundColor = RGB(247, 248, 249);
//    label.layer.cornerRadius = 32;
//    label.layer.masksToBounds = YES;
    label.textColor = RGB(247, 113, 5);
    label.textAlignment = NSTextAlignmentLeft;
    label.font = [UIFont systemFontOfSize:12];
    self.chakanLabel = label ;
    self.chakanLabel.text =@"    查看全部>";
    
    [self.contentView addSubview:label];
    
    
    
    
    
}

-(void)setModel:(HWpinglunModel *)model {
    
    _model = model;
    NSString *content  = @"";
  //  self.neirongtextview.text = @"";
    if (model.beihuifu_user_name == nil  ) {
        content = [NSString stringWithFormat:@"%@:%@",model.user_name, model.content];
    } else {
    
        if ([model.user_name isEqualToString:model.beihuifu_user_name]) {
        
            content = [NSString stringWithFormat:@"%@:%@",model.user_name, model.content];
             
        } else {

            content = [NSString stringWithFormat:@"%@回复%@:%@",model.user_name,model.beihuifu_user_name ,model.content];
        }
        //   content = [NSString stringWithFormat:@"%@回复%@:%@",model.user_name,model.beihuifu_user_name ,model.content];
        
    }

    self.neirongtextview.textColor = RGB(120, 120, 120);
    
     
  //   content = @"四川成家长把孩子送进校园后，纷纷贴墙“暗中观察”。9月1日，全国多地迎来都一小学开学，家长把孩子送进校后，纷纷贴墙“暗中";
    
    CGSize   size2 =    [WMUtil sizeWithFont1:[UIFont systemFontOfSize:14] maxSize:CGSizeMake(kScreenW-60-15-20, 2000) string:content];
    CGFloat a=  8;
  //   self.neirongtextview.text = content;
    if (size2.height < 17) {
       //  a= 10;
        self.neirongtextview.frame =   CGRectMake(60, 0, kScreenW-60-15, size2.height+a);
        
    } else {
        // a=  -10;
        self.neirongtextview.frame =   CGRectMake(60, 0, kScreenW-60-15, size2.height+a);
        
    }
    
    self.neirongtextview.text = content;
 //    self.neirongtextview.frame =   CGRectMake(60, 0, kScreenW-60-15, size2.height+a);

 //    self.neirongtextview.text = content;
    
    if (model.beihuifu_user_name == nil  ) {
        NSString *zifu = [NSString stringWithFormat:@"%@",model.user_name];
        NSRange range1 = [content rangeOfString:zifu];
        [self.neirongtextview  setUnderlineTextWithRange:range1 withUnderlineColor:RGB(0, 0, 0) withClickCoverColor:nil withBlock:^(NSString *clickText) {
            NSLog(@"clickText = %@",clickText);
         //     [self diyigeshijian];
        
        }];
        
    } else {
        NSString *zifu = [NSString stringWithFormat:@"%@",model.user_name];
        NSRange range1 = [content rangeOfString:zifu];
        [self.neirongtextview  setUnderlineTextWithRange:range1 withUnderlineColor:RGB(0, 0, 0) withClickCoverColor:nil withBlock:^(NSString *clickText) {
            NSLog(@"clickText = %@",clickText);
            //  [self diyigeshijian];
            
            
        }];
        
        
        NSString *zifu2 = [NSString stringWithFormat:@"%@",model.beihuifu_user_name];
        NSRange range2 = [content rangeOfString:zifu2];
        [self.neirongtextview  setUnderlineTextWithRange:range2 withUnderlineColor:RGB(0, 0, 0) withClickCoverColor:nil withBlock:^(NSString *clickText) {
            NSLog(@"clickText = %@",@"cdkmcdk");
            [self twoshijian];
             
            
        }];
      
        
    }
    
   
  
    
    
}


- (void)diyigeshijian {
    
    
    NSLog(@"sdgsgdgdggd");
    

    
    HWwenzipinglunViewController *pinglun = [[HWwenzipinglunViewController alloc]init];
   //  pinglun.pid = data.id;
    pinglun.gameIDStr = self.model.gid;
    pinglun.pid =  self.model.id;
    pinglun.ppid = self.frameModel.datamodel.id;
    [[HWViewUtils getCurrentVC].navigationController pushViewController:pinglun animated:YES];
    
    
    
    
}


- (void)twoshijian {
    
    
    NSLog(@"2222222");
    
    
    
    HWwenzipinglunViewController *pinglun = [[HWwenzipinglunViewController alloc]init];
   //  pinglun.pid = data.id;
    pinglun.gameIDStr = self.model.gid;
    pinglun.pid =  self.model.id;
    pinglun.ppid = self.frameModel.datamodel.id;
    [[HWViewUtils getCurrentVC].navigationController pushViewController:pinglun animated:YES];
    
    
}




@end
